#include <iostream>
#include <vector>


class Solution {
public:
    int removeDuplicates(std::vector<int>& nums) {

        int k = 0;// total index
        int tmp_value;// tmp value
        int tmp_count = 0;// count of the same number
        int max_duplicate_count = 2;// max duplicate count
        for (size_t i = 0; i < nums.size(); i++) {
            if (i == 0) {
                k++;
                tmp_value = nums[i];
                tmp_count++;
                continue;
            }
            if (nums[i] == tmp_value) {
                if (tmp_count < max_duplicate_count) {
                    tmp_count++;
                    nums[k] = nums[i];
                    k++;
                } else {
                    continue;
                }
            } else {
                tmp_value = nums[i];
                tmp_count = 1;
                nums[k] = nums[i];
                k++;
            }
        }
        
        return k;
    }
};